home *** CD-ROM | disk | FTP | other *** search
- #include <Events.h>
- #include <memory.h>
- #include <types.h>
- #include <OSUtils.h> /* for SysBeep */
-
- #include <stdio.h>
-
- #include <sys/types.h>
- #include <sys/time.h>
- #include <sys/errno.h>
- #include <sys/socket.h>
- #include <sys/ioctl.h>
- #include <netinet/in.h>
- #include <sys/uio.h>
-
- int spins = 0;
- chasemouse()
- {
- spins++;
- }
-
- main()
- {
- int s;
- struct sockaddr_in her;
- int herlen = sizeof(her);
- int bytes;
- char line[1000];
-
- /* make our socket */
- s = s_socket(AF_INET, SOCK_STREAM, 0);
- if (s < 0)
- {
- perror("socket");
- exit(1);
- }
-
- /* define our spin routine */
- if (s_spinroutine(chasemouse) < 0)
- {
- perror("spinroutine");
- exit(1);
- }
-
- /* connect to the server */
- her.sin_family = AF_INET;
- her.sin_addr.s_addr = 0x0d000ce8 /* 0x8064660a */;
- her.sin_port = htons(25); /* SMTP */
- if (s_connect(s,(caddr_t)&her,sizeof(her)) < 0)
- {
- if (errno != EINPROGRESS)
- {
- perror("connect");
- exit(1);
- }
- }
- dprintf("%d spins after connect\n",spins);
-
- /* wait for the server's greeting */
- bytes = s_read(s,line,sizeof(line)-2);
- if (bytes < 0)
- {
- perror("read");
- exit(1);
- }
- dprintf("%d spins after read\n",spins);
- dprintf("read got %d bytes\n",bytes);
- line[bytes] = '\0';
- dprintf("'%s'\n",line);
-
- /* send our own introduction */
- strcpy(line,"HELO milligan.utcs.utoronto.ca\015\012");
- bytes = s_write(s,line,strlen(line));
- if (bytes <= 0)
- {
- perror("write");
- exit(1);
- }
- dprintf("%d spins after write\n",spins);
-
- /* wait for him to decide he likes us and */
- /* read his approval message (or disapproval...) */
- bytes = s_read(s,line,sizeof(line)-2);
- if (bytes < 0)
- {
- perror("read");
- exit(1);
- }
- dprintf("%d spins after read\n",spins);
- dprintf("read got %d bytes\n",bytes);
- line[bytes] = '\0';
- dprintf("'%s'\n",line);
-
- /* now lets be rude and quit the conversation */
- strcpy(line,"QUIT\015\012");
- bytes = s_write(s,line,strlen(line));
- if (bytes <= 0 && errno != EINPROGRESS)
- {
- perror("write");
- exit(1);
- }
- dprintf("%d spins after write\n",spins);
-
- /* clean up */
- if (s_close(s) < 0)
- {
- perror("close(s)");
- exit(1);
- }
- }
-
-